package site.wenneng.dev.service;

import lombok.extern.slf4j.Slf4j;
import okhttp3.Request;
import okhttp3.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

@Slf4j
@Service
public class AutoTaskService extends BaseService {

    @Autowired
    private WorkingHoursService workingHoursService;

    @Scheduled(cron = "0 0/1 * * * *")
    public void devHeartbeat() {
        Request request = new Request.Builder().url("https://dev.hundsun.com/heppm/notice/getCurrentNotice")
                .post(RequestBody.create("".getBytes()))
                .build();

        invoke(request);
        log.debug("执行效能平台会话保持请求");
    }

    @Scheduled(cron = "0 0 0/6 * * *")
    public void syncWorkingHours() {
        workingHoursService.syncWorkingHours(LocalDate.now().minusWeeks(2), LocalDate.now());
        log.debug("从效能平台同步工时信息完成");
    }
}
